//
//  NowPositionCell.m
//  DaiShengInvest
//
//  Created by 张睿 on 2017/7/5.
//  Copyright © 2017年 davinci. All rights reserved.
//

#import "NowPositionCell.h"
#import "NowPositionViewController.h"

@interface NowPositionCell ()

@property (nonatomic, strong)UILabel * stopLoseLabel;

@property (nonatomic, strong)UILabel * stopWinLabel;

@property (nonatomic, strong)UIButton * topButton;

@property (nonatomic, strong)UIButton * buttomButton;

@property (nonatomic, strong)UIImageView * sellSuccess;

@property (nonatomic, strong)UIImageView * cancelSuccess;

@property (nonatomic, strong)UIView * lineView;

@end

@implementation NowPositionCell


- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    
    if ([super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        
        [self setupUI];
    }
    
    return self;
}



- (void)setChangButtonSTR:(NSString *)changButtonSTR{
    
    _changButtonSTR = changButtonSTR;
    
    if ([_changButtonSTR isEqualToString:@"设置盈亏"]) {
        
        self.cancelSuccess.hidden = YES;
        self.sellSuccess.hidden = YES;
        
        [self.topButton setImage:[UIImage imageNamed:@"设置盈亏"] forState:UIControlStateNormal];
        [self.topButton addTarget:[NowPositionViewController new] action:@selector(didSetWinOrLoseButton) forControlEvents:UIControlEventTouchUpInside];
        
        [self.buttomButton setImage:[UIImage imageNamed:@"平仓"] forState:UIControlStateNormal];
        [self.buttomButton addTarget:[NowPositionViewController new] action:@selector(didSellButton:) forControlEvents:UIControlEventTouchUpInside];
    }else if ([_changButtonSTR isEqualToString:@"修改挂单"]) {
        
        self.cancelSuccess.hidden = YES;
        self.sellSuccess.hidden = YES;
        
        [self.topButton setImage:[UIImage imageNamed:@"修改挂单"] forState:UIControlStateNormal];
        [self.topButton addTarget:[NowPositionViewController new] action:@selector(didChangeOrderButton) forControlEvents:UIControlEventTouchUpInside];
        
        [self.buttomButton setImage:[UIImage imageNamed:@"取消"] forState:UIControlStateNormal];
        [self.buttomButton addTarget:[NowPositionViewController new] action:@selector(didCancelButton:) forControlEvents:UIControlEventTouchUpInside];
    }else if ([_changButtonSTR isEqualToString:@"平仓成功"]){
        
        self.cancelSuccess.hidden = YES;
        self.sellSuccess.hidden = NO;
        
        self.topButton.hidden = YES;
        self.buttomButton.hidden = YES;
        
    }else {
        
        self.cancelSuccess.hidden = NO;
        self.sellSuccess.hidden = YES;
        
        self.topButton.hidden = YES;
        self.buttomButton.hidden = YES;
        
    }
    
}



- (void)setupUI{
    
    self.backgroundColor = [UIColor clearColor];
    
    self.selectionStyle = UITableViewCellSelectionStyleNone;
    
    self.stopLoseLabel = [UILabel new];
    
    self.stopLoseLabel.font = [UIFont fontWithName:@"PingFangSC-Regular" size:13 * SCREENH6];
    self.stopLoseLabel.textColor = ColorWithRGB(0x979797);
    self.stopLoseLabel.textAlignment = NSTextAlignmentLeft;
    self.stopLoseLabel.text = @"止损价";
    
    [self addSubview:self.stopLoseLabel];
    
    [self.stopLoseLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(self).offset(25 * SCREENH6);
        make.top.mas_equalTo(self).offset(10 * SCREENH6);
    }];
    
    self.stopWinLabel = [UILabel new];
    
    self.stopWinLabel.font = [UIFont fontWithName:@"PingFangSC-Regular" size:13 * SCREENH6];
    self.stopWinLabel.textColor = ColorWithRGB(0x979797);
    self.stopWinLabel.textAlignment = NSTextAlignmentLeft;
    self.stopWinLabel.text = @"止盈价";
    
    [self addSubview:self.stopWinLabel];
    
    [self.stopWinLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(self).offset(140 * SCREENH6);
        make.top.mas_equalTo(self.stopLoseLabel);
    }];
    
    self.nowPriceLabel = [UILabel new];
    
    self.nowPriceLabel.font = [UIFont fontWithName:@"PingFangSC-Regular" size:18 * SCREENH6];
    self.nowPriceLabel.textColor = ColorWithRGB(0xffffff);
    self.nowPriceLabel.textAlignment = NSTextAlignmentLeft;
    self.nowPriceLabel.text = @"$6.78131";
    
    [self addSubview:self.nowPriceLabel];
    
    [self.nowPriceLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(self.stopLoseLabel);
        make.top.mas_equalTo(self.stopLoseLabel.mas_bottom).offset(10 * SCREENH6);
    }];
    
    
    self.operationLabel = [UILabel new];
    
    self.operationLabel.font = [UIFont fontWithName:@"PingFangSC-Regular" size:15 * SCREENH6];
    self.operationLabel.textColor = ColorWithRGB(0x1bc360);
    self.operationLabel.textAlignment = NSTextAlignmentLeft;
    self.operationLabel.text = @"看空";
    
    [self addSubview:self.operationLabel];
    
    [self.operationLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(self).offset(180 * SCREENH6);
        make.top.mas_equalTo(self.nowPriceLabel);
    }];
    
    
    self.boundCountLabel = [UILabel new];
    
    self.boundCountLabel.font = [UIFont fontWithName:@"PingFangSC-Regular" size:13 * SCREENH6];
    self.boundCountLabel.textColor = ColorWithRGB(0x979797);
    self.boundCountLabel.textAlignment = NSTextAlignmentLeft;
    self.boundCountLabel.text = @"6.78435--6.77185";
    
    [self addSubview:self.boundCountLabel];
    
    [self.boundCountLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(self.nowPriceLabel);
        make.top.mas_equalTo(self.nowPriceLabel.mas_bottom).offset(10 * SCREENH6);
    }];
    
    self.topButton = [UIButton new];
    
//    [self.topButton setImage:[UIImage imageNamed:@"设置盈亏"] forState:UIControlStateNormal];
//    [self.topButton addTarget:[NowPositionViewController new] action:@selector(didSetWinOrLoseButton) forControlEvents:UIControlEventTouchUpInside];
    
    [self addSubview:self.topButton];
    
    [self.topButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.mas_equalTo(78 * SCREENH6);
        make.height.mas_equalTo(35 * SCREENH6);
        make.top.mas_equalTo(self.stopWinLabel);
        make.trailing.mas_equalTo(self).offset(-15 * SCREENH6);
    }];
    
    self.buttomButton = [UIButton new];
    
//    [self.buttomButton setImage:[UIImage imageNamed:@"平仓"] forState:UIControlStateNormal];
//    [self.buttomButton addTarget:[NowPositionViewController new] action:@selector(didSellButton) forControlEvents:UIControlEventTouchUpInside];
    self.buttomButton.tag = self.tag;
    [self addSubview:self.buttomButton];
    
    [self.buttomButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.mas_equalTo(78 * SCREENH6);
        make.height.mas_equalTo(35 * SCREENH6);
        make.top.mas_equalTo(self.topButton.mas_bottom).offset(10 * SCREENH6);
        make.trailing.mas_equalTo(self.topButton);
    }];
    
    
    self.sellSuccess = [UIImageView new];
    
    self.sellSuccess.image = [UIImage imageNamed:@"平仓成功"];
    
    [self addSubview:self.sellSuccess];
    
    [self.sellSuccess mas_makeConstraints:^(MASConstraintMaker *make) {
        make.trailing.mas_equalTo(self);
        make.width.mas_equalTo(93 * SCREENH6);
        make.height.mas_equalTo(34 * SCREENH6);
        make.centerY.mas_equalTo(self);
    }];
    
    
    self.cancelSuccess = [UIImageView new];
    
    self.cancelSuccess.image = [UIImage imageNamed:@"取消成功"];
    
    [self addSubview:self.cancelSuccess];
    
    [self.cancelSuccess mas_makeConstraints:^(MASConstraintMaker *make) {
        make.trailing.mas_equalTo(self);
        make.width.mas_equalTo(93 * SCREENH6);
        make.height.mas_equalTo(34 * SCREENH6);
        make.centerY.mas_equalTo(self);
    }];
    
    self.lineView = [UIView new];
    
    self.lineView.backgroundColor = [UIColor whiteColor];
    self.lineView.alpha = 0.1;
    
    [self addSubview:self.lineView];
    
    
    [self.lineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.trailing.bottom.mas_equalTo(self);
        make.height.mas_equalTo(1 * SCREENH6);
    }];
    
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
